<%@ page language="java" contentType="text/html;charset=UTF-8"%>
<%@ page import="com.gouwudai.gobbs.pojo.TbbsRule,com.gouwudai.gobbs.pojo.TbbsUserInfo"%>
<%@ include file="../common/common.jsp" %>
<%@ include file="user_pass2.jsp" %>
<%
int businessType = ParamUtils.getIntParameter(request,"type");
String businessTypeName = "积分兑换金币";
if(businessType==1)
    businessTypeName = "积分兑换金币";
else
    businessTypeName = "金币购买积分";

IRuleService ruleService = (IRuleService)BeanManager.getBean("ruleService");
TbbsRule tbbsRule = ruleService.loadByCode("R017");

IUserService userService = (IUserService)BeanManager.getBean("userService");
TbbsUserInfo tbbsUserInfo = userService.load(userLogin.getUserId());

java.math.BigDecimal businessRate = new java.math.BigDecimal(0);
%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title><%=SYSTITLE%> - 交易记录</title>
<meta name="Keywords" content="<%=SYSMETAKEY%>" />
<meta name="Description" content="<%=SYSMETADESC%>" />
<%@ include file="../common/meta.inc" %>
<link rel="stylesheet" type="text/css" href="css/defaultStyle.css" >
<script language="javascript" src="${pageContext.request.contextPath}/scripts/prototype.js"></script>
<script language="javascript" src="${pageContext.request.contextPath}/scripts/buffalo/buffalo.js"></script>
</head>
<body>
<%@ include file="../common/waiting.inc" %>
<SCRIPT language="javascript">

setStatus('<%=SYSTITLE%> - 积分兑换金币');

var END_POINT="${pageContext.request.contextPath}/buffalo";
var buffalo = new Buffalo(END_POINT);
function doSubmit() {
	form = document.theform;	
	if(!validateForm(form))
		return;
		
	var obj = {};
	obj[Buffalo.BOCLASS] = "java.util.HashMap";	
	obj.userId=<%=userLogin.getUserId()%>;
	obj.userName="<%=userLogin.getUserName()%>";
	obj.businessType=<%=businessType%>;
	obj.relatingId=<%=userLogin.getUserId()%>;
	obj.relatingName="<%=userLogin.getUserName()%>";
	obj.businessNum=$F('businessNum');
	obj.businessRate=$F('businessRate');

	obj.opIp="<%=userLogin.getLoginIp()%>";
    buffalo.remoteCall("businessServiceAjaxService.doExchange",[obj], function(reply) {
        ajaxSubmit(reply.getResult(),"兑换成功",true);
    });
}

function validateForm(form)
{
    var exp = /^[0-9]*[1-9][0-9]*$/;
    if(!exp.test(form.businessNum.value))
    {
    	 sl_alert("兑换数目必须为正整数！");
    	 return false;
    }
    <%if(businessType==1) {%>
	    if(parseInt(form.businessNum.value)<parseInt(form.businessRate.value))
	    {
	    	 sl_alert("兑换数目必须大于最小兑率！");
	    	 return false;
	    }   
    <%}%> 
    return true; 
}
</SCRIPT>
<script language="javascript" type="text/javascript" src="template/scripts/topBar.js"></script>
<%@ include file="includes/userMenu.inc" %>
<DIV class="line"></DIV>
<DIV class="list_table_0">
<%=HtmlConst.navMenu("business_exchange.jsp",businessTypeName)%>
</DIV>
<DIV class="line"></DIV>
<form name="theform" id="theform" method="post" action="">
<table width="100%" border="0" align="center" cellpadding="2" cellspacing="1" class="tab">
<tr class="tr">
<td width="160" height="25"><strong>您要操作的项目是</strong></td>
<td height="24"><strong><%=tbbsRule.getRuleName() %></strong></td>
</tr>

<tr><td height="25" class="tab2">您的基本信息：</td>
<td class="tab3">
<strong>信誉:</strong><%=tbbsUserInfo.getUserCredit()%>
&nbsp;&nbsp;
<strong>积分:</strong><%=tbbsUserInfo.getUserMark()%>
&nbsp;&nbsp;
<strong>金币:</strong><%=tbbsUserInfo.getUserMoney()%>
&nbsp;&nbsp;
<strong>存款:</strong><%=tbbsUserInfo.getUserDeposit()%></td></tr>
<%if(businessType==1) {
	businessRate = tbbsRule.getRuleMark();
%>
<tr><td height="25" class="tab2">
当前兑率：
</td><td class="tab3">
<span style="color: #3300FF; font-weight: bold;"><%=businessRate%></span> 积分 兑换 <span style="color: #FF0000; font-weight: bold;">1</span> 个金币
</td>
</tr>
<%}else if(businessType==2){
	businessRate = tbbsRule.getRuleMoney();
%>
<tr><td height="25" class="tab2">
当前兑率：
</td><td class="tab3">
<span style="color: #3300FF; font-weight: bold;">1</span> 个金币 兑换 <span style="color: #FF0000; font-weight: bold;"><%=businessRate%></span> 积分</td>
</tr>
<%}%>

<tr>
  <td height="25" class="tab2">兑换数目：</td>
  <td class="tab3"><input name="businessNum" type="text" id="businessNum" value="0" size="10" maxlength="10">
    (请填写数字否则无法兑换)
  <input name="businessRate" type="hidden" id="businessRate" value="<%=businessRate %>">   
  </td>
</tr>

<tr>
<td height="25" class="tab2">&nbsp;</td>
<td class="tab3">
<%
if(businessRate.intValue()==0){
%>
<span style="color: #FF0000;">此功能暂时关闭</span>
<%}else{%>
<input name="btnSubmit" type="button" class="btn" id="btnSubmit" value="确定兑换" onclick="doSubmit();">
<%}%>
</td>
</tr>
</table>
</form>
<%=COPYRIGHTFOOT%>
<%@ include file="../common/foot.inc"%>
</body>
</html>